import Vue from 'vue'
import {appRouter,R} from './router'
import Router from 'vue-router'
import iView from 'iview';
import Cookies from 'js-cookie';
import store from '../store';

Vue.use(Router);

const RouterConfig = {
  mode: 'history',
  routes: R
};

export const router = new Router(RouterConfig);

router.beforeEach((to, from, next) => {
  iView.LoadingBar.start();
  if (to.matched.some(r => r.meta.requireAuth)) {
    if (store.state.token) {
      console.info(store.state.token);
      next();
    }
    else {
      next(/*{
       name: 'login'
       }*/)
    }
  }
  else {
    next();
  }
});

router.afterEach(() => {
  iView.LoadingBar.finish();
  window.scrollTo(0, 0);
});
